package com.gluxen.dao.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gluxen.dao.BaseDao;

@Repository
public class UserDao extends BaseDao implements IUserDao{
	@Override
	public boolean validateNickName(String nickname){
		boolean ret = false;
		
		StringBuffer hql = new StringBuffer();
		hql.append("select count(a.id) from User a where a.isDelete = 0");
		hql.append(" and a.nickname = :nickname");

		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("nickname", nickname);

		Long count = this.getTotalCount(hql.toString(), map);
		if(count > 0)
			ret = true;
		return ret;
	}

	@Override
	public boolean validateOpenID(String openID) {
		boolean ret = false;
		
		StringBuffer hql = new StringBuffer();
		hql.append("select count(a.id) from User a where a.isDelete = 0");
		hql.append(" and a.openID = :openID");

		Map<Object, Object> map = new HashMap<Object, Object>();
		map.put("openID", openID);

		Long count = this.getTotalCount(hql.toString(), map);
		if(count > 0)
			ret = true;
		return ret;
	}
}